import { asyncRoutes, constantRoutes } from '@/router/index'

const state = {
  route: [] // 动态路由
}

const mutations = {
  // 保存动态路由
  setRoute(state, route) {
    // 将静态路由和动态路由拼接在一起
    state.route = [...constantRoutes, ...route]
  }
}

const actions = {
  filterList(store, menus) {
    const route = asyncRoutes.filter(item => {
      return menus.indexOf(item.name) !== -1
    })
    store.commit('setRoute', route)
    return route
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

